import cookie from '@/utils/auth.js'
import store from '@/store/index.js'
export default {
	namespaced: true,
	state: {
	
		
		isLogin: false,
		token: cookie.get('Token'),
		userinfo: cookie.get('UserInfo'),
		userbalance: {},
		coupon: {},			//次卡体验券
		
		bankCardList:[],  //银行卡信息
		bankCardOb:{},  //银行卡信息
		nowBank:{},
	
	},
	mutations: {
		
		SET_LOGIN(state, status) {
			state.isLogin = status;
		},
		
		SET_BANKCARD(state, Ob) {
			state.bankCardOb = Ob
		},
		SET_NOWBANK(state,nowBank){
			state.nowBank = nowBank
		},
		SET_BANKCARDList(state, list) {
			state.nowBank = list[0]
			state.bankCardList = list
		},
		
		//登陆TOKEN
		SET_TOKEN(state, token) {
			state.token = token;
			cookie.set('Token', token)
		},
		//用户信息
		SET_USERINFO(state, info) {
			state.userinfo = info;
			cookie.set('UserInfo', info)
		},
		//用户余额
		SET_USERBALANCE(state, balance) {
			state.userbalance = balance;
		},
		//次卡体验券
		SET_CARD(state, balance) {
			state.coupon = balance
		},
		//退出登陆
		REMOVE_TOKEN(state) {
			state.token = '';
			state.userinfo = {};
			state.userbalance = {};
			state.usercard = {};
			state.bankCardList = [];
			state.bankCardOb = {};
			state.nowBank = {};
			cookie.remove('Token')
			
		},
		CLEAR_INFO(state) {
			state.userinfo = {};
			state.userbalance = {};
			state.usercard = {};
			state.bankCardList = [];
			state.bankCardOb = {};
			state.nowBank = {};
			cookie.remove('salesman')
		},
	},
	getters: {

	},
	actions: {
		exit({ state, commit }) {
			return new Promise((resolve, reject) => {
				commit('REMOVE_TOKEN')
				store.commit('address/CLEAR')
				store.commit('goods/CLEAR')
				setTimeout(() => {
					resolve(true)
				}, 1000)
			})
		},
		exit2({ state, commit }) {
			return new Promise((resolve, reject) => {
				commit('REMOVE_TOKEN')
				store.commit('address/CLEAR')
				store.commit('goods/CLEAR')
				resolve(true)
			})
		},
	}
}